require(['init'], function () {
  var uid;
  var currentid;
    $.ajax({
      url:"/api/user/current",
      type:"get",
      async:false,
      success:function(data){
        uid=data.data.userid;
      }
    })
    $.ajax({
      url:"/api/student/user/"+uid,
      type:"get",
      async:false,
      success:function(data){
         currentid=data.data.studentuid;
      }
    })
  $('.formContent').find('input').css('width','200px');

  $.fn.extend({
     txtaAutoHeight: function () {
       return this.each(function () {
        var $this = $(this);
        if (!$this.attr('initAttrH')) {
             $this.attr('initAttrH', $this.outerHeight());
         }
         setAutoHeight(this).on('input', function () {
             setAutoHeight(this);
         });
       });
       function setAutoHeight(elem) {
         var $obj = $(elem);
         return $obj.css({ height: $obj.attr('initAttrH'), 'overflow-y': 'hidden' }).height(elem.scrollHeight);
      }
    }
  });
  $(function () {
    $("#remark").txtaAutoHeight();
  });
  getdata();
  function getdata() {
        $.ajax({
            url: '/api/student/' + currentid,
            method:'get',
            success: function (data) {
                var birthday=data.data.birthday;
                $('[name=name]').val(data.data.name);
                $('[name=birthday]').val(birthday==null?" ":birthday.substr(0,10));
                $('[name=email]').val(data.data.email);
                $('[name=mobile]').val(data.data.mobile);
                $('[name=email]').val(data.data.email);
                $('[name=ClassInNo]').val(data.data.ClassInNo);
                $('[name=remark]').val(data.data.remark);
            }
        })
    }
  $('#post').on('click',function(){
    var name=$('[name=name]').val();
    var birthday=$('[name=birthday]').val();
    var email=$('[name=email]').val();
    var mobile=$('[name=mobile]').val();
    var email=$('[name=email]').val();
    var ClassInNo =$('[name=ClassInNo]').val();
    var remark=$('[name=remark]').val();
    var arr = {
      name: name,
      birthday: birthday,
      email: email,
      mobile: mobile,
      email: email,
      ClassInNo: ClassInNo,
      remark: remark
    }
    ajaxMethod({
        url: '/api/student/' + currentid,
        method:'put',
        data:arr,
        success:function(data){
          window.location.reload();
        }
      })
    })

})
